﻿using System;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Reflection;
namespace Data
{
	 	//Manageadmin
		public class Manageadmin
	{
            private DataAccess Access = new Data.DataAccess();
		/// <summary>
        /// 主键
        /// </summary>
        private readonly string primaryKey= "Id";
		/// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public long Add(Model.Manageadmin model)
        {
            return new DataAccess().Add<Model.Manageadmin>(model, primaryKey);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(Model.Manageadmin model)
        {
            return new DataAccess().Update<Model.Manageadmin>(model, primaryKey);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public bool Delete(long Id)
        {
            return new DataAccess().Delete<Model.Manageadmin>(Id, primaryKey);
        }
        /// <summary>
        /// 单条
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Model.Manageadmin GetModel(long Id)
        {
            return new DataAccess().Get<Model.Manageadmin>(Id, primaryKey);
        }
        /// <summary>
        /// 总数据数
        /// </summary>
        /// <returns></returns>
        public int GetAll_Count()
        {
            return new DataAccess().GetCount<Model.Manageadmin>(primaryKey);
        }
        /// <summary>
        /// 抽取分页数据
        /// </summary>
        public List<Model.Manageadmin> GetPageList_Where(int PageIndex, int PageSize, string u_password,out int totalCount)
        {          
            string strWhere = GetSqlWhere(u_password);
            totalCount = new DataAccess().GetCount<Model.Manageadmin>(primaryKey, strWhere);
            return new DataAccess().GetPage_List<Model.Manageadmin>(PageIndex, PageSize, primaryKey, primaryKey+" desc", strWhere);
        }
        /// <summary>
        /// 拼接条件
        /// </summary>
        public string GetSqlWhere(string u_password)
        {
            StringBuilder sqlWhere = new StringBuilder();

            sqlWhere.Append(" 1>0");

            if (!string.IsNullOrEmpty(u_password) && !string.IsNullOrEmpty(u_password.Trim()))
            {
                sqlWhere.Append(" and u_password like '%" + u_password + "%'");
            }         
            return sqlWhere.ToString();
        }
        /// <summary>
        /// 批删
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        public int Drop(string Ids)
        {
            return new DataAccess().Drop<Model.Manageadmin>(Ids, primaryKey);
        }
        public Model.Manageadmin GetOneBynickname(string nickname)
        {
            if (!string.IsNullOrEmpty(nickname) && !string.IsNullOrEmpty(nickname.Trim()))
            {
                System.Data.Common.DbParameter[] p = new System.Data.Common.DbParameter[0];
                StringBuilder sqlWhere = new StringBuilder();
                sqlWhere.Append(" nickname='" + nickname.Trim() + "' AND uesrState<>0");
                return Access.Get<Model.Manageadmin>(sqlWhere.ToString(), p);
            }
            else
            {
                return null;
            }
        }
	}
}